package com.stox.core.manager;

import java.util.Collections;
import java.util.List;

import com.stox.core.dao.BarDao;
import com.stox.core.model.Bar;
import com.stox.core.model.IBar;
import com.stox.core.ui.swing.util.ThrowableReporter;
import com.stox.ioc.Container;

public class BarManager {

	private BarDao barDao;
	
	public BarManager() {
		this.barDao = Container.get(BarDao.class);
	}
	
	public List<IBar> get(String scripCode, String exchangeCode){
		try {
			return barDao.get(scripCode, exchangeCode);
		} catch (Exception e) {
			ThrowableReporter.report(e);
		}
		return Collections.emptyList();
	}
	
	public void persist(List<Bar> bars){
		try{
			barDao.persist(bars);
		}catch(Exception e){
			ThrowableReporter.report(e);
		}
	}
	
	public void persistBatch(List<Bar> bars, String scripCode, String exchangeCode){
		try{
			barDao.persistBatch(bars, scripCode, exchangeCode);
		}catch(Exception e){
			ThrowableReporter.report(e);
		}
	}
	
	public List<Bar> get(String scripCode, String exchangeCode, int count){
		try {
			return barDao.get(scripCode, exchangeCode, count);
		} catch (Exception e) {
			ThrowableReporter.report(e);
		}
		return Collections.emptyList();
	}
}
